﻿
Imports System.IO
Imports xmlctrl
Imports xhtmlctrl

Public Class body2
    Inherits body

    Private _bodyarea As div = Nothing
    Private internalAttributes As Int64 = 0
    Private bodyareaInternalAttributes As Int64 = 0

    Public Sub increaseBodyAreaInternalAttributes(Optional ByVal c As Int64 = 1)
        bodyareaInternalAttributes += c
    End Sub

    Public Sub increaseInternalAttributes(Optional ByVal c As Int64 = 1)
        internalAttributes += c
    End Sub

    Public Function bodyarea() As div
        assert(Not _bodyarea Is Nothing, "_bodyarea is nothing.")
        Return _bodyarea
    End Function

    Public Overrides Sub addchild(ByVal ctrl As xmlcontrol)
        bodyarea().addchild(ctrl)
    End Sub

    Public Sub addchildtobody(ByVal c As xmlcontrol)
        MyBase.addchild(c)
    End Sub

    Public Sub New(Optional ByVal buff As Stream = Nothing)
        MyBase.New(buff)
        _bodyarea = New div(buff)
        _bodyarea.id = "body2_area"
        increaseBodyAreaInternalAttributes()
        MyBase.addchild(bodyarea())
    End Sub

    'special logic for frameset
    Protected Overrides Function render(ByVal compress As Boolean) As Boolean
        'there is always an ID attribute
        If bodyarea().children().size() > 0 OrElse _
           bodyarea().attributes().size() > bodyareaInternalAttributes OrElse _
           attributes().size() > internalAttributes OrElse _
           Not bodyarea().text() Is Nothing OrElse _
           Not text() Is Nothing Then
            Return MyBase.render(compress)
        Else
            Return True
        End If
    End Function

End Class
